import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import manager.AppTaskManager;
import model.oanda.Order;
import play.Application;
import play.GlobalSettings;
import play.Logger;
import play.Play;
import play.libs.Akka;
import scala.concurrent.duration.FiniteDuration;
import akka.actor.Cancellable;

public class Global extends GlobalSettings {

	Cancellable job;

	// List<Order> orders;

	public void onStart(Application app) {
		Logger.info("Application has started");

		// try {

		// WS.client()
		// .url("https://www.stockpair.com/session/authenticate?json")
		// .setQueryParameter("email", "michele.zanotto.1981@gmail.com")
		// .setQueryParameter("password", "QWEzxcasd123")
		// .setMethod("POST")
		// .execute()
		// .map(Test01::sentiment1);
		//

		// .map(Test01::EUR_USD_SENTIMENT)
		// .map(Test01::GBP_USD_SENTIMENT);

		// Document doc =
		// Jsoup.connect("https://www.stockpair.com/session/authenticate?json")
		// .data("email", )
		// .data("password", "QWEzxcasd123")
		// .userAgent("Mozilla")
		// .cookie("auth", "token").timeout(3000).post();
		//
		// Logger.debug(doc.html());

		// } catch (IOException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }

		// orders=new LinkedList<Order>();

		//if (Play.isProd()) {
			job = Akka
					.system()
					.scheduler()
					.schedule(FiniteDuration.create(5l, TimeUnit.MINUTES),
							FiniteDuration.create(5l, TimeUnit.MINUTES),

							// new Runnable() {
							// public void run() {
							// //file.delete();
							// }
							// }

							new AppTaskManager(), Akka.system().dispatcher());
		//}

	}

	public void onStop(Application app) {
		Logger.info("Application shutdown...");
		if (job != null && job.isCancelled())
			job.cancel();

	}

}